package com.mlethe.library.widget.seattable;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

/**
 * 座位
 * Created by Mlethe on 2018/10/17.
 */
public class Seat implements Parcelable {

    /**
     * 座位不可用、座位已售、座位已选中、座位可选
     */
    public static final int SEAT_TYPE_NOT_AVAILABLE = 0, SEAT_TYPE_SOLD = 1, SEAT_TYPE_SELECTED = 2, SEAT_TYPE_AVAILABLE = 3;

    /**
     * 过道、单人座、双人座（情侣座）、保留座、残疾人座、vip会员座、震动座
     */
    public static final int ROAD = 0, SINGLE_PERSON_SEAT = 1, DOUBLE_MAN_SEAT = 2, RETAIN_SEAT = 3, DEFORMITY_SEAT = 4, VIP_SEAT = 5, VIBRATE_SEAT = 6;
    /**
     * 座位id
     */
    private String seatId;
    /**
     * 座位价格
     */
    private double price;
    /**
     * 坐标x
     */
    private int x;
    /**
     * 坐标y
     */
    private int y;
    /**
     * 行
     */
    private String row;
    /**
     * 列
     */
    private String column;
    /**
     * 座位类型
     */
    private int type;
    /**
     * 状态：0->不可用、3->可选、1->已订、2->选中
     */
    private int state;

    /**
     * 情侣座偏移量   -1 上一个   1 下一个
     */
    private String loveSeats = "";

    public Seat(String seatId, int x, int y, String row, String column, int type, int state, String loveSeats) {
        this.seatId = seatId;
        this.x = x;
        this.y = y;
        this.row = row;
        this.column = column;
        this.type = type;
        this.state = state;
        if (loveSeats == null) {
            this.loveSeats = "";
        } else {
            this.loveSeats = loveSeats;
        }
    }

    public Seat(String seatId, int x, int y, String row, String column, int type, int state) {
        this.seatId = seatId;
        this.x = x;
        this.y = y;
        this.row = row;
        this.column = column;
        this.type = type;
        this.state = state;
    }

    public Seat(String seatId, String row, String column, int type, int state, String loveSeats) {
        this.seatId = seatId;
        this.row = row;
        this.column = column;
        this.type = type;
        this.state = state;
        if (loveSeats == null) {
            this.loveSeats = "";
        } else {
            this.loveSeats = loveSeats;
        }
    }

    public String getSeatId() {
        return seatId;
    }

    public void setSeatId(String seatId) {
        this.seatId = seatId;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public String getRow() {
        return row;
    }

    public void setRow(String row) {
        this.row = row;
    }

    public String getColumn() {
        return column;
    }

    public void setColumn(String column) {
        this.column = column;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
    }

    public String getLoveSeats() {
        return loveSeats;
    }

    public void setLoveSeats(String loveSeats) {
        if (loveSeats == null) {
            this.loveSeats = "";
        } else {
            this.loveSeats = loveSeats;
        }
    }

    public boolean isEmpty(){
        return state == SEAT_TYPE_NOT_AVAILABLE && (TextUtils.isEmpty(row) || TextUtils.isEmpty(column));
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof Seat){
            Seat seat = (Seat) obj;
            if (!TextUtils.isEmpty(row) && !TextUtils.isEmpty(column) && row == seat.row && column == seat.column) {
                return true;
            }
            return false;
        } else {
            return super.equals(obj);
        }
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.seatId);
        dest.writeDouble(this.price);
        dest.writeInt(this.x);
        dest.writeInt(this.y);
        dest.writeString(this.row);
        dest.writeString(this.column);
        dest.writeInt(this.type);
        dest.writeInt(this.state);
        dest.writeString(this.loveSeats);
    }

    protected Seat(Parcel in) {
        this.seatId = in.readString();
        this.price = in.readDouble();
        this.x = in.readInt();
        this.y = in.readInt();
        this.row = in.readString();
        this.column = in.readString();
        this.type = in.readInt();
        this.state = in.readInt();
        this.loveSeats = in.readString();
    }

    public static final Creator<Seat> CREATOR = new Creator<Seat>() {
        @Override
        public Seat createFromParcel(Parcel source) {
            return new Seat(source);
        }

        @Override
        public Seat[] newArray(int size) {
            return new Seat[size];
        }
    };
}
